import { _decorator, assetManager, Component, director, EditBox, Label, math, Node, ProgressBar, sys } from 'cc';
import { AudioManager } from './manager/AudioManager';
import { Config } from './manager/Config';
const { ccclass, property } = _decorator;

@ccclass('MenuSceneController')
export class MenuSceneController extends Component {

    @property(Node)
    inputPanelNode: Node = null;
    @property(EditBox)
    nameInputField: EditBox = null;
    @property(Label)
    NameLabel: Label = null;
    @property(ProgressBar)
    progressBar: ProgressBar = null;
    protected start(): void {
        this.updateNameUI();
    }
   
    onChangeNameButtonClick() {
        this.inputPanelNode.active = !this.inputPanelNode.active;
        let name: string = sys.localStorage.getItem('Name');
        this.nameInputField.string = name;
        AudioManager.Instance.playClip(Config.btn_click);
    }
    onSubmitButtonClick() {
        sys.localStorage.setItem('Name', this.nameInputField.string);
        this.inputPanelNode.active = false;
        this.updateNameUI();
        AudioManager.Instance.playClip(Config.btn_click);
    }
    updateNameUI() {
        let name: string = sys.localStorage.getItem('Name');
        this.NameLabel.string = name;
    }
    onAdventureModeButtonClick() {
        AudioManager.Instance.playClip(Config.btn_click);
        this.progressBar.node.active = true;
        director.preloadScene('03-GameScene',(completedCount:number,totalCount:number)=>{
            let progress:number=completedCount/totalCount; 
            this.progressBar.progress=progress;
        },()=>{
            director.loadScene('03-GameScene');
        })
    }
}


